/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;
import Entity.Author;
import Entity.Employee;
import Entity.User;
import iface.IModel;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author BinhNV_A04911
 */
public class AuthorListModel extends AbstractTableModel implements IModel<Author> {

    private manager.Manager  manager;
    public AuthorListModel(manager.Manager authorManager){
       this.manager = manager;
    }

    public int getRowCount() {
        int count = 0;
        for (int i = 0; i < this.manager.getAuthorManager().size();i++) {
            count++;
        }
        return count;
    }

    public int getColumnCount() {
        return 2;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Author obj = this.manager.getAuthorManager().get(rowIndex);
        User  objUser = this.manager.getUserManager().getById(obj.getAuthorID());
        Employee objEmployee = this.manager.getEmployeeManager().getById(obj.getAuthorID());
        switch(columnIndex){
            case 0:
                  return obj;
            case 1:
              obj.getAuthorName();
            case 2:
                return this.manager.getAuthorManager().getById(obj.getAuthorID()).getAuthorName();
                default:
                    return null;

        }
    }

    public void add(Author obj) {
        this.manager.getAuthorManager().add(obj);
        this.fireTableDataChanged();
    }

    public void replace(int index, Author obj) {
        this.manager.getAuthorManager().replace(index, obj);
        this.fireTableDataChanged();
    }

    public void remove(Author obj) {
       this.manager.getAuthorManager().remove(obj);
        this.fireTableDataChanged();
    }

    public void refresh() {
        this.fireTableDataChanged();
    }

    public Author get(int index) {
       return this.manager.getAuthorManager().get(index);
    }


}
